
package com.doc2video.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doc2video.common.Result;
import com.doc2video.dto.VideoGenerateDTO;
import com.doc2video.entity.Video;
import com.doc2video.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 视频Controller
 */
@Api(tags = "视频管理")
@RestController
@RequestMapping("/video")
public class VideoController {

    @Autowired
    private VideoService videoService;

    @ApiOperation("生成视频")
    @PostMapping("/generate")
    public Result<String> generateVideo(@Validated @RequestBody VideoGenerateDTO generateDTO, 
                                       HttpServletRequest request) {
        return videoService.generateVideo(generateDTO, request);
    }

    @ApiOperation("分页查询用户视频列表")
    @GetMapping("/list")
    public Result<Page<Video>> getUserVideos(@RequestParam(defaultValue = "1") Integer current,
                                           @RequestParam(defaultValue = "10") Integer size,
                                           HttpServletRequest request) {
        Page<Video> page = new Page<>(current, size);
        return videoService.getUserVideos(page, request);
    }

    @ApiOperation("根据ID查询视频")
    @GetMapping("/{id}")
    public Result<Video> getVideoById(@PathVariable Long id, HttpServletRequest request) {
        return videoService.getVideoById(id, request);
    }

    @ApiOperation("下载视频")
    @GetMapping("/{id}/download")
    public Result<byte[]> downloadVideo(@PathVariable Long id, HttpServletRequest request) {
        return videoService.downloadVideo(id, request);
    }

    @ApiOperation("删除视频")
    @DeleteMapping("/{id}")
    public Result<String> deleteVideo(@PathVariable Long id, HttpServletRequest request) {
        return videoService.deleteVideo(id, request);
    }

    @ApiOperation("获取视频生成进度")
    @GetMapping("/{id}/progress")
    public Result<Integer> getVideoProgress(@PathVariable Long id, HttpServletRequest request) {
        return videoService.getVideoProgress(id, request);
    }

    @ApiOperation("重新生成视频")
    @PostMapping("/{id}/regenerate")
    public Result<String> regenerateVideo(@PathVariable Long id, HttpServletRequest request) {
        return videoService.regenerateVideo(id, request);
    }
}
